package com.webmeeting.chat.wordchat.servlets;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import com.myframework.utils.logutil.WMLogger;
import com.webmeeting.chat.wordchat.events.WordChatMessageInbound;

public class WordChatInitServlet extends HttpServlet {

	private static final long	serialVersionUID	= 1L;
	
	private static List<WordChatMessageInbound> onlineUserList;

	@Override
	public void init(ServletConfig config) throws ServletException {
		super.init(config);
		onlineUserList = new ArrayList<WordChatMessageInbound>();
		WMLogger.debug("Initialize the online user list.");
	}
	
	public static synchronized List<WordChatMessageInbound> getOnlineUserList() {
		return onlineUserList;
	}
	
	public static synchronized void addOnlineUser(WordChatMessageInbound user) {
		if (null != onlineUserList) {
			onlineUserList.add(user);
		} else {
			onlineUserList = new ArrayList<WordChatMessageInbound>();
			onlineUserList.add(user);
		}
		WMLogger.debug("Add an online user");
		
	}
	
	public static synchronized void removeOnlineUser(WordChatMessageInbound user) {
		if (null != onlineUserList) {
			onlineUserList.remove(user);
		} else {
			onlineUserList = new ArrayList<WordChatMessageInbound>();
		}
		WMLogger.debug("Remove an online user");
	}
	
	public static synchronized void removeAllOnlineUser() {
		if (null != onlineUserList) {
			onlineUserList.clear();
		} else {
			onlineUserList = new ArrayList<WordChatMessageInbound>();
		}
		WMLogger.debug("Remove an online user");
	}

}
